#!/bin/bash
#SBATCH --job-name=MSE6701
#SBATCH --partition=64c512g
#SBATCH -N 1
#SBATCH --ntasks-per-node=4
#SBATCH --output=%j.out
#SBATCH --error=%j.err

. ../../0-tools/environment

module load intel-oneapi-compilers/2021.4.0
module load intel-oneapi-mpi/2021.4.0
module load intel-oneapi-mkl/2021.4.0

ulimit -s unlimited

# Define the output file and its header
outfile='eng_a.dat'
echo '#vol/atom energy(eV/cell) a(ang) mag(mu) time-used(seconds)' > ${outfile}

# Loop over a
for a in `seq 2.70 0.02 2.96`
do
# Prepare POSCAR
cat > POSCAR << EOF
BCC Fe - primitive cell
${a}
0.5 0.5 -0.5
-0.5 0.5 0.5
0.5 -0.5 0.5
Fe
1
Direct
0.0 0.0 0.0
EOF

# Run vasp
mpirun ${VASP}

# Collect info
nat=`grep 'NIONS' OUTCAR |tail -1|awk '{print $12}'`
vol=`grep ' volume of cell' OUTCAR |tail -1|awk -v n=${nat} '{print $5/n}'`
eng=`grep 'free  energy' OUTCAR | awk -v n=${nat} '{print $5/n}'`
mag=`grep 'mag=' OSZICAR |awk '{print $10}'`
sec=`grep 'Total CPU time used' OUTCAR |awk '{print $6}'`
echo "$vol $eng $a $mag $sec" >> ${outfile}

rm -rf WAVECAR

done

# Clean up
rm -rf CHG CHGCAR CONTCAR DOSCAR EIGENVAL IBZKPT OSZICAR OUTCAR PBS.batch PCDAT vasprun.xml XDATCAR REPORT
